/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sambi.mvc.model;

import com.sambi.mvc.controller.InvoicesSearchController;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Habib
 */
@Entity
@Table(name = "invoicessearchmodel")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "InvoicesSearchModel.findAll", query = "SELECT i FROM InvoicesSearchModel i"),
    @NamedQuery(name = "InvoicesSearchModel.findByCustomerId", query = "SELECT i FROM InvoicesSearchModel i WHERE i.customerId = :customerId"),
    @NamedQuery(name = "InvoicesSearchModel.findByCustomerName", query = "SELECT i FROM InvoicesSearchModel i WHERE i.customerName = :customerName")})
public class InvoicesSearchModel extends AbstractModel implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "customerId")
    private Integer customerId;
    @Column(name = "customerName")
    private String customerName;
    @JoinColumn(name = "nbInvoices", referencedColumnName = "id")
    @ManyToOne
    private Invoice nbInvoices;

    public InvoicesSearchModel() {
    }

    public InvoicesSearchModel(Integer customerId) {
        this.customerId = customerId;
    }

    public Integer getCustomerId() {
        return customerId;
    }

    public void setCustomerId(Integer customerId) {
        Integer oldCustomerId = this.customerId;
        this.customerId = customerId;
        firePropertyChange(InvoicesSearchController.CUSTOMERID_PROPERTY, oldCustomerId, customerId);
    }

    public void setCustomerName(String customerName) {
        String oldCustomerName = this.customerName;
        this.customerName = customerName;
        firePropertyChange(InvoicesSearchController.CUSTOMERNAME_PROPERTY, oldCustomerName, customerName);
    }

    public String getCustomerName() {
        return customerName;
    }

    public Invoice getNbInvoices() {
        return nbInvoices;
    }

    public void setNbInvoices(Invoice nbInvoices) {
        Invoice old = this.nbInvoices;
        this.nbInvoices = nbInvoices;
        firePropertyChange(InvoicesSearchController.NBINVOICES_PROPERTY, old, nbInvoices);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (customerId != null ? customerId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof InvoicesSearchModel)) {
            return false;
        }
        InvoicesSearchModel other = (InvoicesSearchModel) object;
        if ((this.customerId == null && other.customerId != null) || (this.customerId != null && !this.customerId.equals(other.customerId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.sambi.mvc.model.Invoicessearchmodel[ customerId=" + customerId + " ]";
    }

}
